/**
 * 差分账号管理初始化
 */
var Account = {
    id: "AccountTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Account.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '账号Id', field: 'accountId', visible: true, align: 'center', valign: 'middle'},
            {title: '账号', field: 'account', visible: true, align: 'center', valign: 'middle'},
            {title: '密码', field: 'password', visible: true, align: 'center', valign: 'middle'},
            {title: '用户Id', field: 'userId', visible: true, align: 'center', valign: 'middle'},
            {title: '服务类型(购买的账号类型)RTD;RTK', field: 'serviceType', visible: true, align: 'center', valign: 'middle'},
            {title: '开始时间(计费开始)', field: 'startTime', visible: true, align: 'center', valign: 'middle'},
            {title: '购买时长(单位月)', field: 'payTime', visible: true, align: 'center', valign: 'middle'},
            {title: '绑定状态(0否;1是)', field: 'bindingState', visible: true, align: 'center', valign: 'middle'},
            {title: '系统标识', field: 'systemSign', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '更新时间', field: 'updateTime', visible: true, align: 'center', valign: 'middle'},
            {title: '删除标记', field: 'flag', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Account.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Account.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加差分账号
 */
Account.openAddAccount = function () {
    var index = layer.open({
        type: 2,
        title: '添加差分账号',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/account/account_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看差分账号详情
 */
Account.openAccountDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '差分账号详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/account/account_update/' + Account.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除差分账号
 */
Account.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/account/delete", function (data) {
            Feng.success("删除成功!");
            Account.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("accountId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询差分账号列表
 */
Account.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Account.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Account.initColumn();
    var table = new BSTable(Account.id, "/account/list", defaultColunms);
    table.setPaginationType("client");
    Account.table = table.init();
});
